<?php
    //todo ��ȡ�ͻ��˵���������
    @$username=$_REQUEST['username'];
    //todo ����mysql���ݿ�
   // $conn=mysqli_connect('127.0.0.1','root','','mm',3306);
   $conn = mysqli_connect(SAE_MYSQL_HOST_M, SAE_MYSQL_USER, SAE_MYSQL_PASS,  SAE_MYSQL_DB, SAE_MYSQL_PORT);
    //todo �����������
    $sql='SET NAMES UTF8';
    mysqli_query($conn,$sql);
    //todo ��ѯmysql���ݿ��еĶ��������
    $sql="SELECT * FROM mm_orders WHERE user_name='$username'";
    //todo ���ؽ��������
    $result=mysqli_query($conn,$sql);
    //todo �������������
    $orderList=[];//todo ���������

    while($order=mysqli_fetch_assoc($result)){
        //todo Ϊ�Զ������������Ʒ��Ϣ������
        $order['productList']=[];
        //todo �õ���ǰ������idֵ
        $oid=$order['order_id'];
        //todo ���²�ѯ
        $sql="SELECT * FROM mm_product WHERE pid IN (SELECT product_id FROM mm_order_product_detail WHERE order_id='$oid')";
        $presult=mysqli_query($conn,$sql);

        while($p=mysqli_fetch_assoc($presult)){
            array_push($order['productList'],$p);
        }

        //todo $order->ÿһ����¼���ݿ�����
        array_push($orderList,$order);
    }
    //todo ��Ӧ���ͻ��˵����ݸ�ʽΪJSON
    header('Content-Type:application/json');
    echo json_encode($orderList);
?>